
import 'package:dio/dio.dart';
import 'package:wu_you/data/repository/trad_repository.dart';
import 'package:wu_you/model/user/trad_model.dart';

import 'http_bloc.dart';

///产品列表
class TradTypesBloc extends HttpBloc<List<TradTypeModel>> {
  @override
  Future<List<TradTypeModel>> obtainData(HttpEvent event) {
    return TradRepository().getTradTypes();
  }
}



///发布信息
class PublishInfoBloc extends HttpBloc<TradPubInfo> {
  @override
  Future<TradPubInfo> obtainData(HttpEvent event) {
    if (event is IdHttpEvent) {
      return TradRepository().getPublishInfo(event.id);
    }
    return Future.error("参数错误");
  }
}


///收款方式查询
class PaymentInfoBloc extends HttpBloc<PaymentInfo> {
  @override
  Future<PaymentInfo> obtainData(HttpEvent event) {
    if (event is IdHttpEvent) {
      return TradRepository().getPaymentInfo(event.id);
    }
    return Future.error("参数错误");
  }
}




class TradOrdersEvent extends HttpEvent {
  final String wid;
  final int size;

  TradOrdersEvent({this.wid, this.size});

  @override
  List<Object> get props => [wid, size];
}

///产品订单
class TradOrdersBloc extends HttpBloc<TradOrders> {
  @override
  Future<TradOrders> obtainData(HttpEvent event) {
    if (event is TradOrdersEvent) {
      return TradRepository().getTradOrders(event.wid,event.size);
    }
    return null;
  }
}




///订单展开事件
class TradOrderExpEvent extends HttpEvent {
  final String size;
  final String wid;
  final String price;
  final String type;
  TradOrderExpEvent({this.size,this.wid,this.price,this.type});
  @override
  List<Object> get props => [size,wid,price, type];
}

///订单展开列表
class TradOrderExpBloc extends HttpBloc<List<TradOrderExp>> {
  @override
  Future<List<TradOrderExp>> obtainData(HttpEvent event) {
    if (event is TradOrderExpEvent) {
      return TradRepository().getTradExpList(event.size,event.wid,event.price,event.type);
    }
    return Future.error("参数错误");
  }
}





///我的广告列表事件
class MyAdListEvent extends PageSizeHttpEvent {
  final String status;
  MyAdListEvent({this.status,int page, int size = 10}) : super(page, size);
  @override
  List<Object> get props => [status,page, size];
}

///我的广告列表
class MyAdListBloc extends HttpBloc<List<MyAdOrders>> {
  @override
  Future<List<MyAdOrders>> obtainData(HttpEvent event) {
    if (event is MyAdListEvent) {
      return TradRepository().getMyAdList(event.status,event.page,event.size);
    }
    return Future.error("参数错误");
  }
}


///我的广告订单详情
class OrderItemInfoBloc extends HttpBloc<TradOrderDetail> {
  @override
  Future<TradOrderDetail> obtainData(HttpEvent event) {
    if (event is IdHttpEvent) {
      return TradRepository().getAdDetailInfo(event.id);
    }
    return Future.error("参数错误");
  }
}



///所有收款方式
class PaymentAllBloc extends HttpBloc<List<PayMethodStatus>>{
  @override
  Future<List<PayMethodStatus>> obtainData(HttpEvent event) {
    if (event is PageSizeHttpEvent) {
      return TradRepository().getPaymentAll();
    }
    return Future.error(DioError(error: "参数错误",requestOptions: null));
  }
}
